package cn.xuqiudong.console.module.timer.schedule.signin.handler;

import cn.xuqiudong.common.base.craw.CrawlConnect;
import org.jsoup.Connection;
import org.jsoup.HttpStatusException;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;

import java.io.IOException;
import java.util.Map;

/**
 * 描述:
 *    每周一个蘑菇 shakes and fidget
 * @author Vic.xu
 * @since 2024-06-24 11:46
 */
public class ShakesAndFidgetHandler extends AbstractSignInHandler{


    public static void login() throws IOException {
        String url = "https://home.sfgame.net/api/shop/setServer?server=w39.sfgame.net&characterid=tQDwKW2k%23413";
        Connection.Response execute = new ShakesAndFidgetHandler().con(url).execute();
        String body = execute.body();
        LOGGER.info("S&F login result body : {}", body);
        Map<String, String> cookies = execute.cookies();
        Map<String, String> headers = execute.headers();
        LOGGER.info("S&F login result headers : {}", headers);
        LOGGER.info("S&F login result cookies : {}", cookies);

        String getMushroom = "https://home.sfgame.net/api/shop/checkout?identifier=psp_webshop_20_item_1&countrycode=en&affiliatecode=";
        String bodyText = new ShakesAndFidgetHandler().con(getMushroom).header(headers).cookie(cookies).getBodyText();
        LOGGER.info("S&F get Mushroom result bodyText : {}", bodyText);
    }

    public static void main(String[] args) throws IOException {
        login();
        /*CrawlConnect crawlConnect = CrawlConnect.build("https://xuqiudong.cn/aa");
        Connection.Response execute = crawlConnect.execute();
        System.out.println(execute.statusCode());
        System.out.println(execute.statusMessage());
        System.out.println(execute.body());*/
//        test();
    }

    public static void test(){
        String url = "https://xuqiudong.cn/aa";

        try {
            // 发送请求并获取响应
            Connection.Response response = Jsoup.connect(url)
                    .method(Connection.Method.GET)
                    .execute();

            // 获取状态码
            int statusCode = response.statusCode();
            System.out.println("HTTP 状态码: " + statusCode);

            // 获取文档内容
            Document document = response.parse();
            System.out.println("网页标题: " + document.title());

        } catch (HttpStatusException e) {
            e.printStackTrace();
            // 捕获 HTTP 状态异常并获取状态码
            int statusCode = e.getStatusCode();
            String localizedMessage = e.getLocalizedMessage();
            System.out.println("请求失败，HTTP 状态码: " + statusCode + "  localizedMessage =" + localizedMessage);
        } catch (Exception e) {
            System.out.println("请求失败");
            e.printStackTrace();
        }
    }



}
